
//  standard C headers

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/mman.h>
#include <math.h>
#include <getopt.h>
#include <time.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/shm.h>
#include <pthread.h>
#include <sys/time.h>

#ifndef _MEPHISTO_CAM_H_
#define _MEPHISTO_CAM_H_

//  User defined headers
#include "COMMON.h"
#include "REG_BITS.h"

#include "ADS5294.h"
#include "AD9508.h"
#include "DACx0508.h"
#include "ADG714.h"
#include "SPI.h"
#include "SPI_PS.h"
#include "Float_SPI_PS.h"
#include "MISC.h"
#include "BONN_SHUTTER.h"
#include "ADC2REG_CLK.h"

#include "Daisy.h"

#include "float2bin.h"

//  Ini parser
#include "dictionary.h"
#include "iniparser.h"

#include "CCD290_DRV_Config.h"	// added @2022-12-11 by XYH

// #include "CAM_Socket.h"
// #include "CMDs.h"

#include "ReadOut.h"

typedef struct _pthread_data {
    struct sockaddr_in  client_addr;
    int                 sock_fd;            //  socket hander
    int                 *socket_cnt;        //  指向全局变量，保存/更新socket连接数
    pthread_t           *tid_exposure;      //  保存曝光线程的id 
    int                 *abort_exposure;    //  指向全局变量，控制是否终止曝光
} pthread_data;

// typedef struct _SockInfo {
//     struct sockaddr_in addr;
//     int fd;
// }SockInfo;

void *serveForClient(void * arg);

void startExposure(void *arg);

void abortExposure(void *arg);

// #define REG_NUM CCD290_DRV_CONFIG_PARAM_NUM

typedef struct _MephistoCAM_Config{

    ccd290_drive_config *config_ccd_drive;

    char dcds_config_file[1024];    // 记录DCDS参数配置文件

    uint32_t n_row;
    uint32_t n_col;
    uint32_t n_bytes;        // 图像保存至DDR时，每个像元占的字节数

    uint32_t *gpio_flt_ctrl;
    uint32_t *gpio_flt_data;

    uint32_t *gpio_in;
    uint32_t *gpio_pl_ps;

    uint32_t *gpio_out;
    uint32_t *gpio_out2;

    uint32_t *gpio_spi_ps_ctrl;
    uint32_t *gpio_spi_ps_data;

} MephistoCAM_Config;


int init_MephistoCAM_Config( MephistoCAM_Config *cfg, char *config_path );
int free_MephistoCAM_Config( MephistoCAM_Config *cfg );

#endif // _MEPHISTO_CAM_H_
